package com.effectiv.panchoo.controller;

import java.security.Principal;
import java.util.Date;

import javax.inject.Inject;

import lombok.extern.slf4j.Slf4j;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hazelcast.core.HazelcastInstance;

@Slf4j
@Controller
public class ChatController {
	
	@Inject
	private HazelcastInstance hc;
	
	@MessageMapping("/chat")
    @SendTo("/topic/chat")
	public Chat handle(Chat chat, Principal principal) {
		
		System.out.println("Chat = " + chat + " || Principal = " + principal.getName());
		
		chat.setTime(new Date());
		//TODO change to spring security user
		chat.setUser(principal.getName());
		
		return chat;
	}
	
	@RequestMapping("/signin")
	public String gotoLogin(){
		log.info("--------------------------SINGIN CONTROLLER CALLED -------------------------");
		
		return "login";
	}
	
	@RequestMapping("/home")
	public String gotoHome(Principal principal){
		log.info("--------------------------HOME CONTROLLER CALLED -------------------------");
		
		System.out.println(" || Principal = " + principal.getName());
		
		//get the name of the default room for this user
		//for now assume its kolkata
		
		
		
		return "home";
	}
}
